package Operation;

import Book.Book;
import Book.BookList;

import java.util.Scanner;

public class DelBook implements IOperation{

    @Override
    public void work(BookList bookList) {

        System.out.println("请输入你要删除的书：");
        Scanner scanner = new Scanner(System.in);
        String name = scanner.nextLine();

        for (int i = 0; i < bookList.getUsedSize(); i++) {
            Book book = bookList.getPos(i);
            if(name.equals(book.getName())){
                int j;
                for (j = i; j < bookList.getUsedSize()-1; j++) {
                    Book book1 = bookList.getPos(j+1);
                    bookList.setBooks(book1,j);
                }
                bookList.setBooks(null,j);
                bookList.setUsedSize(bookList.getUsedSize()-1);
                System.out.println("删除成功！");
                return;
            }
        }
        System.out.println("没有找到这本书");
    }
}
